home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / pgm_util / regmax / regmax.bas < prev    next >
Encoding:
BASIC Source File  |  1995-01-03  |  5.4 KB  |  164 lines

  1. '   ******************************************************
  2. '   //THIS MODULE (REGMAX.BAS) IS DESIGNED TO BE INCLUDED IN YOUR
  3. '   //OWN PROJECT, AND CONTAINS ALL THE GBLIB2 FUNCTIONS
  4. '   //NECESSARY TO WRITE AND READ REGISTRATION DATA.
  5. '   //IT MUST BE USED IN CONJUNCTION WITH GBLIB2.EXE.
  6. '   //REGMAX.EXE, REGMAX.BAS (c)1995 Gordon Bamber//
  7. '   ******************************************************
  8.  
  9. Option Explicit
  10. '   /* Modified 02/01/95 [GB] */
  11. '   /* Modified 31/12/94 [GB] */
  12. '   /* Created 31/12/94 [GB] */
  13.  
  14. '   //Declares for the API in GBLIB2.EXE//
  15.  
  16. '   //This function is a crude string -> number algorithm//
  17. '   //It can be used to make a checksum of the registration information//
  18. Declare Function MakeAKey Lib "GBLIB2.EXE" (ByVal AString As String) As Long
  19.  
  20.  
  21. '   //These two functions must NOT be used in development mode//
  22. '   //on this project, because they are designed to//
  23. '   //modify REGMAX.EXE file directly, and until it has been//
  24. '   //compiled, there is no REGMAX.EXE to modify!
  25. Declare Function WriteRegData Lib "GBLIB2.EXE" (ByVal sz_Name As String, ByVal sz_Org As String, ByVal sz_EXEPath As String, ByVal MyPhrase As String) As Integer
  26. '**** Line below changed 02/01/95 [GB] ****
  27. Declare Function ReadRegData Lib "GBLIB2.EXE" (ByVal sz_EXEPath As String, ByVal sz_Name As String, ByVal sz_Org As String, ByVal YMD As String, NameLen As Integer, OrgLen As Integer) As Integer
  28.  
  29. '   //These Subs simply show information//
  30. Declare Sub ShowWinDir Lib "GBLIB2.EXE" ()
  31. Declare Sub ShowSysDir Lib "GBLIB2.EXE" ()
  32.  
  33. '   //Registration variables//
  34. Global USERNAME As String
  35. Global USERORG As String
  36. Global BRANDDATE As String
  37.  
  38. '   //Data constant//
  39. Global Const MONTHSTRING = "JanFebMarAprMayJunJulAugSepOctNovDec"
  40.  
  41. '   //WIN31 API Function to bar accidents in development mode!//
  42. Declare Function FindWindow Lib "User" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
  43.  
  44. Sub DevMsg ()
  45.  
  46. '   /* Modified 31/12/94 [GB] */
  47. '   /* Created 31/12/94 [GB] */
  48.  
  49. '   //This message is shown if ISVBRUNNING returns true//
  50.  
  51. Dim msg As String
  52. msg = "You are working in Development Mode" & Chr$(10) & Chr$(10)
  53. msg = msg & "I cannot therefore read or write data" & Chr$(10)
  54. msg = msg & "to or from REGMAX.EXE," & Chr$(10)
  55. msg = msg & "because you havn't compiled it yet!" & Chr$(10)
  56. msg = msg & "Compile REGMAX.EXE, and run it outside" & Chr$(10)
  57. msg = msg & "of the Visual Basic IDE entirely."
  58. MsgBox msg, 48, "REGMAX - Get / PutDataIntoEXE"
  59. End Sub
  60.  
  61. Sub GetDataFromEXE ()
  62.  
  63. '   /* Modified 02/01/95 [GB] */
  64. '   /* Modified 30/12/94 [GB] */
  65. '   /* Created 30/12/94 [GB] */
  66.  
  67. '   //Quit out in development mode//
  68. If ISVBRUNNING() <> 0 Then
  69.     DevMsg
  70.     Exit Sub
  71. End If
  72.  
  73. Dim i_RetValue As Integer
  74. Dim sz_EXEPath As String
  75. Dim NameLen As Integer
  76. Dim OrgLen As Integer
  77. Dim TUserName As String
  78. Dim TUserOrg As String
  79. Dim YMD As String
  80.  
  81. '   //Get the full path and filename of this application//
  82. sz_EXEPath = App.Path
  83. If Right$(sz_EXEPath, 1) <> "\" Then sz_EXEPath = sz_EXEPath & "\"
  84. sz_EXEPath = sz_EXEPath & App.EXEName & ".EXE"
  85.  
  86. '   //You MUST initialise the strings to this length or VB cannot//
  87. '   //cope with passing strings to/from the GBLIB2 API//
  88. TUserName = String$(42, 0)
  89. TUserOrg = String$(34, 0)
  90. YMD = String$(4, 0)
  91.  
  92. '   //Read the Information from the EXE//
  93. i_RetValue = ReadRegData(sz_EXEPath, TUserName, TUserOrg, YMD, NameLen, OrgLen)
  94. '   //Return value is Zero if sz_EXEPath_EXEPath is branded OK//
  95.  
  96. '   //If the EXE is 'virgin' then X=1 and USERNAME and USERORG = 'UNLICENSED' //
  97. USERNAME = Left$(TUserName, NameLen)
  98. USERORG = Left$(TUserOrg, OrgLen)
  99.  
  100. '   //Now process the DATE information//
  101. '   //If the EXE is virgin then YMD is all spaces//
  102. If Left$(YMD, 1) = " " Then Exit Sub
  103.  
  104. '   //YMD = The Year-Month-Date in ASCII codes//
  105. '   //Here I unpack the YMD data into the 'English' form of dd mmmm yyyy//
  106.  
  107. '   //1) Day//
  108. BRANDDATE = Format$(Asc(Mid$(YMD, 3, 1)), "#0")
  109.  
  110. '   //2) Month//
  111. BRANDDATE = BRANDDATE & " " & Mid$(MONTHSTRING, (Asc(Mid$(YMD, 2, 1))) * 3 - 2, 3)
  112.  
  113. '   //3) Year//
  114. '   //NOTE it is returned as (YY+108)//
  115. BRANDDATE = BRANDDATE & " 19" & Format$(Asc(Left$(YMD, 1)) - 108, "00")
  116. End Sub
  117.  
  118. Function ISVBRUNNING () As Integer
  119.  
  120. '   /* Modified 31/12/94 [GB] */
  121. '   /* Created 31/12/94 [GB] */
  122.  
  123. '   //Simple test to see if VB is in development mode//
  124. If FindWindow("wndclass_desked_gsk", "Microsoft Visual Basic [run]") > 0 Then
  125.     ISVBRUNNING = 1
  126. Else
  127.     ISVBRUNNING = 0
  128. End If
  129. End Function
  130.  
  131. Sub PutDataIntoEXE (AName As String, AnOrganisation As String, sz_Key As String)
  132.  
  133. '   /* Modified 31/12/94 [GB] */
  134. '   /* Created 31/12/94 [GB] */
  135.  
  136. '   //OPTIONAL//
  137. '   //Quit if running in development mode//
  138. If ISVBRUNNING() <> 0 Then
  139.     DevMsg
  140.     Exit Sub
  141. End If
  142.  
  143. Dim i_RetValue As Integer
  144. Dim sz_EXEPath As String
  145.  
  146. '   //OPTIONAL//
  147. '   //Build up the full path to this application//
  148. sz_EXEPath = App.Path
  149. If Right$(sz_EXEPath, 1) <> "\" Then sz_EXEPath = sz_EXEPath & "\"
  150. sz_EXEPath = sz_EXEPath & App.EXEName & ".EXE"
  151.  
  152. '   //NOTE: sz_EXEPath could be set to any VB3 program, not//
  153. '   //just this one.
  154.  
  155. '   //Do the deed. Note that AName and AnOrganisation will be truncated//
  156. '   //if they are over 33 or 41 characters respectively//
  157.  
  158. i_RetValue = WriteRegData(AName, AnOrganisation, sz_EXEPath, sz_Key)
  159. '   //Return value is zero for success/
  160. '   //Return value is 1 if either item has been truncated//
  161.  
  162. End Sub
  163.  
  164.